package shared.file

object MockRuntimeImpl  {
  
  val instance = new shared.runtime.Runtime {
    
    println("creating new instance")
    
  val host = "local"
  
  val username = "user"
  
  val filesystem = new shared.file.Filesystem
  filesystem.addFolder(new java.io.File("target"))
  
  val channelName = "channel"
  
  @volatile var messageBuffer: List[shared.message.Message] = Nil
  
  val channel = new shared.runtime.ChannelAdaptor {
    import shared.message._
    import org.jgroups.Address
    
    def localAddress = new org.jgroups.stack.IpAddress(java.net.InetAddress.getLocalHost, 5151)
    
    def send(add: Address, m:Message) = {
      synchronized {
        messageBuffer = m :: messageBuffer
      }
    }
  }
  
  val responseHandler = channel
  
  def remove = {
    if(messageBuffer.isEmpty) None
    else {
      synchronized {
        val h = messageBuffer.firstOption
        messageBuffer = messageBuffer.tail
        h        
      }
    }
  }
  
  server.start
  
  }
  
  
  
}
